From 198214367eff70b5e021057d121025b2f80e19f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Wed, 10 Nov 2010 16:53:09 +0100
Subject: [PATCH] Allow login name up to LOGIN_NAME_MAX length

POSIX mandates 9 bytes minimal length including trailing '\0'
(limits.h:_POSIX_LOGIN_NAME_MAX). Current GNU/Linux run time limit is 256
(getconf LOGIN_NAME_MAX).

This patch removes hard-coded 40 bytes limit.
---
 mingetty.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/mingetty.c b/mingetty.c
index dbc2cce..327e630 100644
--- a/mingetty.c
+++ b/mingetty.c
@@ -299,10 +299,21 @@ static void do_prompt (int showlogin)
 
 static char *get_logname (void)
 {
-	static char logname[40];
+	long int logname_size;
+	static char *logname = NULL;
+	char *logname_new;
 	char *bp;
 	unsigned char c;
 
+	logname_size = sysconf (_SC_LOGIN_NAME_MAX);
+	if (logname_size <= 0)
+		error ("Could not get maximal login name length");
+
+	logname_new = realloc (logname, logname_size);
+	if (!logname_new)
+		error ("Not enough memory");
+	logname = logname_new;
+
 	tcflush (0, TCIFLUSH);		/* flush pending input */
 	for (*logname = 0; *logname == 0;) {
 		do_prompt (1);
@@ -319,8 +330,9 @@ static char *get_logname (void)
 			} else if (!isprint (c))
 				error ("%s: invalid character 0x%x in login"
 					" name", tty, c);
-			else if ((size_t)(bp - logname) >= sizeof (logname) - 1)
-				error ("%s: too long login name", tty);
+			else if ((bp - logname) >= (logname_size - 1))
+				error ("%s: too long login name "
+					"(limit is %ld B)", tty, logname_size);
 			else
 				*bp++ = c;
 		}
-- 
1.7.3.2

